home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 43
/
Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso
/
-serious-
/
hardware
/
camedia
/
camprg.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-06-14
|
17KB
|
678 lines
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <dos/dos.h>
#include <exec/exec.h>
#include <devices/serial.h>
#include <jpeg/jpeg.h>
#include <cybergraphics/cybergraphics.h>
#include <intuition/intuition.h>
#include <libraries/asl.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>
#include <clib/jpeg_protos.h>
#include <clib/cybergraphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/asl_protos.h>
#include <pragma/dos_lib.h>
#include <pragma/exec_lib.h>
#include <pragma/jpeg_lib.h>
#include <pragma/cybergraphics_lib.h>
#include <pragma/intuition_lib.h>
#include <pragma/asl_lib.h>
#include "Camedia.h"
struct Library *JpegBase, *CyberGfxBase;
void info_f(enum Camera_Speed cs, char* error_msg);
void preview_f(enum Camera_Speed cs, char* error_msg);
void do_f(int user_min, int user_max, char *name, long speed, Camera_Speed cs, int action, char* error_msg);
void main(int argc, char *argv[]) {
enum arg {
NONE = -2,
WRONG_MODE = -1,
DEVICE = 0,
UNIT,
SPEED,
INFO,
PREVIEW,
TAKE_PICTURE,
RETR,
THUMBNAILS,
DEL,
FROM,
TO,
NAME};
char *input_mask = "DEVICE/K,UNIT/N,SPEED/N,INFO/S,PREVIEW/S,TAKE_PICTURE/S,RETR/S,THUMBNAILS/S,DEL/S,FROM/N,TO/N,NAME/K";
enum Camera_Speed cs;
long speed=0;
int from, to, i, unit, modus = NONE;
LONG array[12];
struct RDArgs *rdargs;
char devicename[256], picture_name[256], error_msg[256];
*error_msg=0;
for (i=0; i<12; i++) array[i]=0;
rdargs=ReadArgs(input_mask, array, NULL);
if (rdargs==NULL) {
printf("An error occured in ReadArgs(%s, array, NULL);\n", input_mask);
exit(0);
}
/* DEVICE/K */
if (array[DEVICE]==0) strcpy(devicename, "serial.device");
else strcpy(devicename, (char *) array[DEVICE]);
/* UNIT/N */
if (array[UNIT]!=0) unit=*((long *) array[UNIT]);
else unit=0;
/* SPEED/N */
if (array[SPEED]==0) {
speed=19200;
cs=CAMERA_SPEED_19200;
} else {
speed=*((long *) array[SPEED]);
switch (speed) {
case 9600:
cs=CAMERA_SPEED_9600;
break;
case 19200:
cs=CAMERA_SPEED_19200;
break;
case 38400:
cs=CAMERA_SPEED_38400;
break;
case 57600:
cs=CAMERA_SPEED_57600;
break;
case 115200:
cs=CAMERA_SPEED_115200;
break;
default:
// cs=CAMERA_SPEED_Unknown;
printf("Unknown speed, must be either 9600, 19200, 38400, 57600 or 115200\n");
exit(0);
}
}
/* INFO/S */
if ((int) array[INFO]) modus=INFO;
/* PREVIEW/S */
if ((int) array[PREVIEW]) {
if (modus!=NONE) {
printf("Choose exactly one mode!\n");
modus=WRONG_MODE;
} else
modus=PREVIEW;
}
/* TAKE_PICTURE/S */
if ((int) array[TAKE_PICTURE]) {
if (modus!=NONE) {
printf("Choose exactly one mode!\n");
modus=WRONG_MODE;
} else
modus=TAKE_PICTURE;
}
/* RETR/S */
if ((int) array[RETR]) {
if (modus!=NONE) {
printf("Choose exactly one mode!\n");
modus=WRONG_MODE;
} else {
modus=RETR;
printf("get Frames ");
}
}
/* THUMBNAILS/S */
if ((int) array[THUMBNAILS]) {
if (modus!=NONE) {
printf("Choose exactly one mode!\n");
modus=WRONG_MODE;
} else {
modus=THUMBNAILS;
printf("get Thumbnails ");
}
}
/* DEL/S */
if ((int) array[DEL]) {
if (modus!=NONE) {
printf("Choose exactly one mode!\n");
modus=WRONG_MODE;
} else {
modus=DEL;
printf("delete Frames ");
}
}
printf("start\n");
if ((modus==RETR) || (modus==THUMBNAILS) || (modus==DEL)) {
/* FROM/N */
if (array[FROM]!=0) from=(int) *((long *) array[FROM]);
else from=0;
/* TO/N */
if (array[TO]!=0) to=(int) *((long *) array[TO]);
else to=0;
/* NAME/K */
if (array[NAME]==0) strcpy(picture_name, "picture");
else strcpy(picture_name, (char *) array[NAME]);
printf("from %d to %d with name %s\n", from, to, picture_name);
}
printf("end\n");
FreeArgs(rdargs);
if (modus==NONE) {
printf("Choose one mode, which is Either INFO, PREVIEW, RETR, THUMBNAILS or DEL\n");
exit(0);
}
bootstrap(devicename, unit, error_msg);
if (*error_msg!=0) {
printf("There was an error in bootstrap: %s\n", error_msg);
exit(0);
}
switch (modus){
case THUMBNAILS:
if (from==0) from=1;
if (to==0) to=255;
do_f(from, to, picture_name, speed, cs, 0, error_msg);
break;
case RETR:
if (from==0) from=1;
if (to==0) to=255;
do_f(from, to, picture_name, speed, cs, 1, error_msg);
break;
case DEL:
if (from==0) from=1;
if (to==0) to=255;
printf("from=%d\n", from);
do_f(from, to, picture_name, speed, cs, 2, error_msg);
break;
case TAKE_PICTURE:
// for this short code, I don't define a seperate function:)
init(cs, error_msg);
if (*error_msg==0) {
TakeAction(AC_Take_Picture, 0, error_msg);
// overwrite timeout_error, which is ok in this single case
*error_msg=0;
}
break;
case PREVIEW:
preview_f(cs, error_msg);
break;
case INFO:
info_f(cs, error_msg);
break;
default:
printf("ops, there is somthing wrong with the mode\n");
}
printf("Well, all done\n");
if (*error_msg!=0) {
printf("There was an error: %s\n", error_msg);
}
clean(100);
}
void info_f(enum Camera_Speed cs, char* error_msg) {
Resolution *re=NULL;
time_t *c=NULL, *TimeDate=NULL;
long *ss=NULL;
Aperture *a=NULL;
Color_Mode *cm=NULL;
Flash_Mode *fm=NULL;
int *noft=NULL, *nofl=NULL, *bc=NULL, *aoht=NULL, *asoft=NULL, *lb=NULL, *lat=NULL;
int *AEL_WBL=NULL, *Fisheye=NULL, *Wide=NULL, *Digital_Zoom=NULL, *BAW=NULL;
int *LCD_Brightness=NULL, *Frames_Taken=NULL,*ProtectionState=NULL, *psof=NULL;
Camera_Speed *ccs=NULL;
Bright_Contrast *brc=NULL;
White_Balance *wb=NULL;
Date_Format *df=NULL;
Exp_Meter *em=NULL;
long *aml=NULL, *locf=NULL, *loct=NULL, *AudioDataLength=NULL;
Lens_Mode *lm=NULL;
int i, max;
char buf[1024];
init(cs, error_msg);
if (*error_msg!=0) return;
Get_Resolution(re, error_msg);
if (*error_msg!=0) return;
printf("Resolution=%s\n", dump_Resolution(*re));
Get_Clock(c, error_msg);
if (*error_msg!=0) return;
printf("Clock=%s\n", asctime(localtime(c)));
Get_Shutter_Speed(ss, error_msg);
if (*error_msg!=0) return;
printf("Shutter_Speed=%d\n", *ss);
/* Get_Aperture(a, error_msg);
if (*error_msg!=0) return;
printf("Aperture=%s\n", dump_Aperture(*a));
*/
Get_Color_Mode(cm, error_msg);
if (*error_msg!=0) return;
printf("Color_Mode=%s\n", dump_Color_Mode(*cm));
Get_Flash_Mode(fm, error_msg);
if (*error_msg!=0) return;
printf("Flash_Mode=%s\n", dump_Flash_Mode(*fm));
Get_Num_of_Frames_Taken(noft, error_msg);
if (*error_msg!=0) return;
printf("Number of Frames Taken=%d\n", *noft);
max=*noft;
Get_Num_of_Frames_Left(nofl, error_msg);
if (*error_msg!=0) return;
printf("Number of Frames Left=%d\n", *nofl);
Get_Battery_Capacity(bc, error_msg);
if (*error_msg!=0) return;
printf("Battery Capacity=%d\n", *bc);
/* Get_Comm_Speed(ccs, error_msg);
if (*error_msg!=0) return;
printf("Comm Speed=%s\n", dump_Comm_Speed(*ccs));
*/
/* Get_Bright_And_Contrast(brc, error_msg);
if (*error_msg!=0) return;
printf("Bright and Contrast=%s\n", dump_Bright_Contrast(*brc));
*/
Get_White_Balance(wb, error_msg);
if (*error_msg!=0) return;
printf("White Balance=%s\n", dump_White_Balance(*wb));
Get_Autoshut_on_Host_Timer(aoht, error_msg);
if (*error_msg!=0) return;
printf("Autoshut on Host Timer=%d\n", *aoht);
Get_Autoshut_on_Field_Timer(asoft, error_msg);
if (*error_msg!=0) return;
printf("Autoshut on Field Timer=%d\n", *asoft);
Get_Available_Memory_Left(aml, error_msg);
if (*error_msg!=0) return;
printf("Available Memory Left=%d [Bytes]\n", *aml);
Get_Lens_Mode(lm, error_msg);
if (*error_msg!=0) return;
printf("Lens Mode=%s\n", dump_Lens_Mode(*lm));
Get_LCD_Brightness(lb, error_msg);
if (*error_msg!=0) return;
printf("LCD Brightness=%d\n", *lb);
Get_LCD_Autoshut_Timer(lat, error_msg);
if (*error_msg!=0) return;
printf("LCD Autoshut Timer=%d\n", *lat);
Get_Date_Format(df, error_msg);
if (*error_msg!=0) return;
printf("Date Format=%s\n", dump_Date_Format(*df));
Get_Exp_Meter(em, error_msg);
if (*error_msg!=0) return;
printf("Exp Meter=%s\n", dump_Exp_Meter(*em));
/* Get_Optical_Mode(AEL_WBL, Fisheye, Wide, Digital_Zoom, BAW, error_msg);
if (*error_msg!=0) return;
printf("AEL_WB=%dL, Fisheye=%d, Wide=%d, Digital_Zoom=%d, BAW=%d\n", *AEL_WBL, *Fisheye, *Wide, *Digital_Zoom, *BAW);
*/
Get_Camera_ID(buf, NULL, error_msg);
if (*error_msg!=0) return;
printf("Camera ID=%s\n", (char *) buf);
Get_Serial_Number(buf, NULL, error_msg);
if (*error_msg!=0) return;
printf("Serial Number=%s\n", buf);
Get_Version(buf, NULL, error_msg);
if (*error_msg!=0) return;
printf("Version=%s\n", buf);
Get_Model((char *) buf, NULL, error_msg);
if (*error_msg!=0) return;
printf("Model=%s\n", buf);
/* Get_Camera_Summery_Data(re, LCD_Brightness, Frames_Taken, error_msg);
if (*error_msg!=0) return;
printf("Resolution=%s, LCD Brightness=%d, Frames Taken=%d\n", dump(*re), *LCD_Brightness, *Frames_Taken);
*/
Get_Manufacturer((char *) buf, NULL, error_msg);
if (*error_msg!=0) return;
printf("Manufacturer=%s\n", buf);
if (max>0) {
i=1;
printf("There are %d frames taken\n", max);
while (i<=max && i<255) {
printf("Frame[%d]:\n", i);
Get_Length_of_Frame(i, locf, error_msg);
if (*error_msg!=0) return;
printf(" Length=%d\n", *locf);
Get_Length_of_Thumbnail(i, loct, error_msg);
if (*error_msg!=0) return;
printf(" Length of Thumbnail=%d\n", *loct);
Get_Protect_State_of_Frame(i, psof, error_msg);
if (*error_msg!=0) return;
printf(" Protection=%d\n", *psof);
Get_Picture_Summery_Data(i, NULL, NULL, NULL, TimeDate, error_msg);
if (*error_msg!=0) return;
printf(" time stamp=%s\n", asctime(localtime(TimeDate)));
i++;
}
} else printf("There are no pictures in the camera\n");
}
void do_f(int user_min, int user_max, char *picture_name, long speed, enum Camera_Speed cs, int action, char* error_msg) {
time_t t;
time_t time1, time2;
char name[255], comment[80];
int i, max, passedtime, NoFT;
long size;
struct tm *tm_s;
if ((user_min<1) || (user_max<1) || (user_min>user_max)) {
printf("Can't accept such ranges\n");
return;
}
printf("user_min=%d\n", user_min);
init(cs, error_msg);
if (*error_msg!=0) return;
Get_Num_of_Frames_Taken(&NoFT, error_msg);
if (*error_msg!=0) return;
max=(int) NoFT;
if (max==0) {
printf("No pictures are stored in the camera.\n");
return;
}
if (max<user_min) {
printf("There are %d pictures in the camera, not one more.\n", max);
printf("user_min=%d\n", user_min);
return;
}
if (max<user_max) user_max=max;
switch(action) {
case 0:
printf("Will get thumbnails %d to %d\n", user_min, user_max);
break;
case 1:
printf("Will get pictures %d to %d\n", user_min, user_max);
break;
case 2:
printf("Will delete pictures %d to %d\n", user_min, user_max);
break;
default:
printf("action has a wrong value %d\n", action);
}
for(i=user_min; i<=user_max; i++) {
if (action==0) {
sprintf(name, "%s_%d.jpeg", picture_name, i);
Get_Length_of_Thumbnail(i, &size, error_msg);
if (*error_msg!=0) return;
printf("Get thumbnail %d, size %d bytes, transfer time: about %d s\n", i, size, (int) 3+size/(speed/10));
}
if (action==1) {
sprintf(name, "%s_%d.jpeg", picture_name, i);
Get_Length_of_Frame(i, &size, error_msg);
if (*error_msg!=0) return;
printf("Get picture %d, size %d bytes, transfer time: about %d s\n", i, size, (int) 3+size/(speed/10));
}
Get_Picture_Summery_Data(i, NULL, NULL, NULL, &t, error_msg);
if (*error_msg!=0) return;
tm_s = localtime(&t);
if (((tm_s->tm_year)<95) && ((tm_s->tm_year)>105)) strcpy(comment, "no date set");
else strftime(comment, 80, "%d-%b-%Y %H:%M:%S", tm_s );
time(&time1);
switch (action) {
case 0:
save_Thumbnail(i, name, comment, error_msg);
if (*error_msg!=0) return;
break;
case 1:
save_Frame(i, name, comment, error_msg);
if (*error_msg!=0) return;
break;
case 2:
SetIntegerRegister(Cmd_Set_Current_Frame_Number, (L1) i, error_msg);
if (*error_msg!=0) return;
TakeAction(AC_Erase_Current_Frame, 0, error_msg);
if (*error_msg!=0) return;
break;
default:
printf("action has a wrong value %d\n", action);
}
time(&time2);
passedtime=(int) time2-time1;
if ((action==0) || (action==1)) printf("%s, size %d, transfered in %d s, %5.0f cps\n", name, size, passedtime, ((float) size) / ((float) passedtime) );
} // end for
}
void preview_f(enum Camera_Speed cs, char* error_msg) {
struct JPEGDecHandle *jph;
struct Screen *scr;
struct Window *win;
struct Message *msg;
UBYTE *buffer=NULL;
UBYTE *frame_buffer=NULL;
ULONG DisplayID;
UWORD DisplayDepth;
struct ScreenModeRequester *smr;
int err;
ULONG x, y, count, bpp;
UBYTE colorspace;
long *size=0;
BOOL r;
/* Open Libraries */
JpegBase = OpenLibrary( "jpeg.library", NULL );
if (JpegBase==NULL) {
printf("Couldn't open jpeg.library\n");
return;
}
CyberGfxBase = OpenLibrary( "cybergraphics.library", NULL );
if (JpegBase==NULL) {
printf("Couldn't open cybergraphics.library\n");
goto end5;
}
/* Open ASL and ask user about screen */
smr = (struct ScreenModeRequester* ) AllocAslRequestTags(ASL_ScreenModeRequest,
ASLSM_MinDepth, (ULONG) 15,
TAG_DONE);
if (smr==NULL) {
printf("Couldn't do an AllocAslRequestTags()\n");
goto end4;
}
r = AslRequest(smr, TAG_DONE);
if (!r) {
FreeAslRequest(smr);
printf("User did nothing?\n");
goto end4;
}
DisplayID=smr->sm_DisplayID;
DisplayDepth=smr->sm_DisplayDepth;
FreeAslRequest(smr);
/* Open Screen and Window */
scr = OpenScreenTags( NULL,
SA_Title, "Camedia_Snapshot",
//SA_DisplayID, 0x40120051,
SA_DisplayID, DisplayID,
//SA_Depth, GetCyberIDAttr( CYBRIDATTR_DEPTH, 0x40120051),
SA_Depth, DisplayDepth,
TAG_DONE );
if (scr==NULL) {
printf("Couln't open screen\n");
goto end4;
}
win = OpenWindowTags( NULL,
WA_Title, "Preview",
WA_Flags, WFLG_ACTIVATE | WFLG_SIMPLE_REFRESH |
WFLG_SIZEGADGET | WFLG_RMBTRAP | WFLG_DRAGBAR |
WFLG_DEPTHGADGET | WFLG_CLOSEGADGET,
WA_IDCMP, IDCMP_CLOSEWINDOW,
WA_Left, 0,
WA_Top, 0,
WA_Width, 500,
WA_Height, 380,
WA_MinWidth, 100,
WA_MinHeight, 70,
WA_MaxWidth, scr->Width,
WA_MaxHeight, scr->Height,
WA_AutoAdjust, 1,
WA_CustomScreen, scr,
TAG_DONE );
if ( win == NULL ) {
printf("Couldn't open window\n");
goto end3;
}
buffer=(UBYTE *) AllocMem(256000+6000, MEMF_CLEAR);
if (buffer==NULL) {
printf("No memory\n");
goto end2;
}
frame_buffer=buffer+256000;
/* retrieve previews */
init(cs, error_msg);
if (*error_msg!=0) {
printf("Error in init() %s\n", error_msg);
goto end2;
}
for (;;) {
msg=GetMsg( win->UserPort );
if (msg!=NULL) {
ReplyMsg(msg);
while ( ( msg = GetMsg( win->UserPort ) ) != NULL ) ReplyMsg( msg );
goto end1;
}
Get_Preview((UBYTE *) frame_buffer, size, error_msg);
if (*error_msg!=0) {
printf("Error in Get_Preview() %s\n", error_msg);
goto end1;
}
/* Decode picture */
err = AllocJPEGDecompress( &jph,
JPG_SrcMemStream, frame_buffer,
JPG_SrcMemStreamSize, *size,
TAG_DONE );
if (err!=0) {
printf("error in AllocJPEGDecompress\n");
goto end1;
}
err = GetJPEGInfo( jph,
JPG_Width, &x, JPG_Height, &y,
JPG_ColourSpace, &colorspace,
JPG_BytesPerPixel, &bpp,
JPG_ScaleNum, 1, JPG_ScaleDenom, 1,
TAG_DONE );
if (err!=0) {
printf("error in GetJPEGInfo\n");
FreeJPEGDecompress(jph);
goto end1;
}
err = DecompressJPEG( jph,
JPG_DestRGBBuffer, buffer,
JPG_ScaleNum, 1, JPG_ScaleDenom, 1,
TAG_DONE );
if (err!=0) {
printf("error in DecompressJPEG(...)\n");
FreeJPEGDecompress(jph);
goto end1;
}
/* Display picture */
count= (ULONG) ScalePixelArray(buffer, x, y, (bpp*x), win->RPort, win->BorderLeft, win->BorderTop, win->GZZWidth, win->GZZHeight, RECTFMT_RGB);
FreeJPEGDecompress(jph);
}
/* Close Windows and Screen*/
end1:
FreeMem(buffer, 256000+6000);
end2:
CloseWindow(win);
end3:
CloseScreen(scr);
end4:
/* Close Libraries */
CloseLibrary(CyberGfxBase);
end5:
CloseLibrary(JpegBase);
}